﻿using Microsoft.AspNetCore.Mvc;
using Zhp.Api.Attributes;
using Zhp.IService.Sys;
using Zhp.Model.Common;
using Zhp.Model.Sys;

namespace Zhp.Api.Controllers.Sys
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiGroup(GroupName = ApiGroupEnum.Sys)]
    [SeedMenu(MenuGroup = ApiGroupEnum.Sys, Name = "角色管理", RouterName = "role", WebFilePath = "sys/role/index", Icon = "role")]
    public class SysRoleController : ControllerBase
    {
        protected readonly ISysRoleService SysRole;

        public SysRoleController(ISysRoleService SysRole)
        {
            this.SysRole = SysRole;
        }

        [HttpPost]
        [SeedList("角色列表", "角色管理", ApiGroupEnum.Sys)]
        public async Task<PageRet<RoleModel>> Index(RoleQuery query)
        {
            var list = await SysRole.GetRole(query);
            
            return new PageRet<RoleModel>
            {
                DataList = list,
                TotalCount = query.TotalCount,
            };
        }

        [HttpPost]
        [SeedButton("新增", "角色列表", "角色管理", ApiGroupEnum.Sys)]
        public async Task<bool> Create(RoleCreate Role)
        {
            return await SysRole.Create(Role);
        }

        [HttpPut]
        [SeedButton("修改", "角色列表", "角色管理", ApiGroupEnum.Sys)]
        public async Task<bool> Update(RoleCreate Role)
        {
            return await SysRole.Update(Role);
        }

        [HttpDelete("{id}")]
        [SeedButton("删除", "角色列表", "角色管理", ApiGroupEnum.Sys)]
        public async Task<bool> Delete(string id)
        {
            return await SysRole.Delete(id);
        }
    }
}
